#! /bin/bash

#采集日期
if [ $# -eq 0 ]
then
    DATE=`date -d "-1 day" +%Y-%m-%d`
else
    DATE=$1
fi


hive -S -e "
INSERT into itcast_dwm.customer_signup_dwm PARTITION (payment_time_year, payment_time_month, payment_time_day)
SELECT
    dwd.customer_id,
    dwd.origin_type,
    dwd.origin_type_state,
    clazz.itcast_school_id,
    clazz.itcast_school_name,
    clazz.itcast_subject_id,
    clazz.itcast_subject_name,
    e.tdepart_id,
    dept.name as tdepart_name,
    substr(dwd.payment_time, 12, 2) as payment_time_hour,
    substr(dwd.payment_time, 1, 4) payment_time_year,
    substr(dwd.payment_time, 6, 2) payment_time_month,
    substr(dwd.payment_time, 9, 2) payment_time_day
FROM itcast_dwd.customer_relationship_dwd dwd
LEFT JOIN itcast_dimen.itcast_clazz clazz on dwd.itcast_clazz_id=clazz.id
LEFT JOIN itcast_dimen.employee e on dwd.creator=e.id
LEFT JOIN itcast_dimen.scrm_department dept on e.tdepart_id=dept.id
where substr(dwd.payment_time, 1, 10) >= '${DATE}' ;"